<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    [#if !haskey ]
    <link href="/res/back/css/base.css" rel="stylesheet" type="text/css"/>
    <link href="/res/third/bootstrap3/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
    <script src="/res/common/js/jquery.1.9.1.min.js" type="text/javascript"></script>
    <script src="/res/third/artDialog/jquery.artDialog.js" type="text/javascript"></script>
    <script src="/res/third/validate/jquery.validate.js" type="text/javascript"></script>
    [/#if]
    <title>匹配仓库管理</title>
</head>
<body>
<div class="panel panel-info panel-content">
    <!-- Default panel contents -->
    <div class="panel-heading">
        [#--<button type="button" class="btn btn-info" id="addButton" onclick="addRole();">--]
            [#--<span class="glyphicon glyphicon-"></span>&nbsp;新增--]
        [#--</button>--]
        <button type="button" class="btn btn-danger" id="addButton" onclick="deleteMore();">
            <span class="glyphicon glyphicon-minus"></span>&nbsp;批量删除
        </button>
            <input type="button"  class="btn btn-danger" onclick="newAdd()" value="+新增" style="float: right"/>
    </div>
    <!-- Table -->
    <table class="table  table-hover table-striped table-bordered">
        <thead>
        <tr>
            <th width="50"><input type="checkbox" class="check_all"/></th>
            <th width="80">序号</th>
            <th style="text-align: center" width="200">类目名称</th>
            <th>标题</th>
            <th style="text-align: center" width="200">创建时间</th>
            <th style="width:150px;">操作</th>
        </tr>
        </thead>
        <tbody class="retbody">
        [#list p.list as rep]
        <tr>
            <td align="center"><input type="checkbox" _rep="${rep.id!}"/></td>
            <td align="center">${rep_index+1}</td>
            <td align="center">${rep.proCategory.name}</td>
            <td align="center">${rep.title!}</td>
            <td align="center">${rep.createtime!?string('yyyy-MM-dd')}</td>
            <td align="center">
                [#--<button type="button" class="btn btn-info btn-xs edits" onclick="edit(${rep.id} , '${rep.title}')">编辑</button>--]
                <button type="button" class="btn btn-danger btn-xs delbtn" onclick="del(${rep.id})">删除</button>
            </td>
        <tr>
        [/#list]
        </tbody>
    </table>
    <div class="panel-footer">
        [@fenye p = p form = 'reForm' mulity='reMu' /]
    </div>
</div>

<div id="add" style="display:none;">
    <form id="signupForm" class="form-horizontal"  method="post" role="form">
        <div class="form-group">
            <input type="hidden" name="pid" id="pid">
            <label>类目名称:</label>
            <input type="button"  value="选择类目" onclick="chooseCate()">
            <span id="pidName" style="color:blue"></span>
        </div>
        <div class="form-group">
            <label>标题:</label>
            <input id="title"  style="height:26px" name="title">
        </div>
        <div class="form-group" style="margin-top: 10px;">
            <div style="text-align: center;">
                <button onclick="addsub();" type="button" class="btn btn-info">确认</button>
            </div>
        </div>
    </form>
</div>

<script type="text/javascript">

    var cdialog;
    function chooseCate(pid) {
        pid=pid||'';
        cdialog=art.dialog.load("选择所属类目","/category/v_choose_category.do?curent="+pid);
    }

         function chooseCallback(name, id,topid) {
       	  cdialog.close();
        	  $('#pid').val(id);
        	  $('#pidName').text(name);
    }

[#if haskey ]
    function ${mulity!}refeshthis(){
        $.messager.progress({
            text : "loadding",
            interval : 100
        });
        $("#center").load('/repository/v_list.do' , $("form[id='${form!'infoForm'}']").serialize() , function(){
            $.messager.progress('close');
        });
    }

    function ${mulity!}go(pageNo){
        $("input[name='pageNo']").val(pageNo);
        ${mulity!}refeshthis();
    }
    function ${mulity!}refresh(){
        ${mulity!}go(${p.pageNo});
    }
[/#if]


    $(".check_all").click(function () {
        if (this.checked) {
            $(".retbody input[type='checkbox']").prop("checked", true);
        } else {
            $(".retbody input[type='checkbox']").prop("checked", false);
        }
    });


    function deleteMore() {
        if ($(".retbody input[type='checkbox']:checked").length > 0) {
            var ids = [];
            $(".retbody input[type='checkbox']:checked").each(function () {
                ids.push($(this).attr("_rep"));
            });
            artDialog.confirm('是否确认批量删除', function () {
                $.ajax({
                    url: '/repository/o_delete_more.do',
                    type: 'post',
                    dataType: 'json',
                    data: {rids: ids.join(",")},
                    success: function (data) {
                        if (data.success) {
                            reMurefresh();
                        } else {
                            artDialog.alert(data.msg, function () {
                                reMurefresh();
                            });
                        }
                    }
                });
            });
        } else {
            artDialog.alert("请选择", function () {
            });
        }
    }

    function categorygo(pageNo) {
        $("#repositoryinfoForm input[name='pageNo']").val(pageNo);
    }
    function categoryrefresh() {
        categorygo(${p.pageNo});
    }

    function newAdd() {
        dialog=art.dialog({
            title:"新增匹配",
            width:500,
            lock:true,
            content:document.getElementById("add")

        });
    }

    function addsub(){
        if(($("#pid").val().trim())==""){
            alert("请输入类目");
            return;
        }
        var title=$('#title').val().trim();
        if(title==""){
            alert("请输入标题");
            return;
        }
        
        $.ajax({
            type:"post",
            dataType:"json",
            data:$("#signupForm").serialize(),
            url:'/repository/o_newadd.do',
            success:function(aj){
                if(aj.success){
                    location.reload();
                    alert(aj.msg);
                }
            }
        });
    }

    function del(id) {
        artDialog.confirm('是否确认删除', function () {
            $.ajax({
                url: '/repository/o_del.do',
                type: 'post',
                dataType: 'json',
                data: {
                    id: id
                },
                beforeSend: function () {
                    //art.dialog.tips("删除中...");
                },
                success: function (data) {
                    if (data.success) {
                        reMurefresh();
                    } else {
                        artDialog.alert(data.msg, function () {
                            reMurefresh();
                        });
                    }
                }
            });
        });
    }
</script>
</body>
</html>